import 'package:flutter/cupertino.dart';
import 'package:smart_devices/utils/colors.dart';

class DrawTopLine extends StatefulWidget {
  final Widget child;

  final Color? color;


  const DrawTopLine(
      {super.key, required this.child, this.color});

  @override
  State<DrawTopLine> createState() => _DrawTopLineState();
}

class _DrawTopLineState extends State<DrawTopLine> {
  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      painter: _DrawLineColorPainter(
          color: widget.color ?? ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2)          ),
      child: widget.child,
    );
  }
}

class _DrawLineColorPainter extends CustomPainter {
  final Color color;

  _DrawLineColorPainter({required this.color});

  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..style = PaintingStyle.stroke
      ..color = color
      ..strokeWidth = 1;
    canvas.drawLine(Offset.zero, Offset(size.width, 0), paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return this != oldDelegate;
  }
}
